﻿<UserControl x:Class="Commanding.Modules.Order.Views.OrdersEditorView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:prism="http://www.codeplex.com/prism"
    xmlns:converter="clr-namespace:Commanding.Modules.Order.Converter"
    Width="Auto" Height="Auto" >
    <UserControl.Resources>
        <converter:DateConverter x:Key="dateConverter"/>
        <converter:StringToNullableNumberConverter x:Key="stringToNullableNumberConverter" />
        <converter:NullToVisibilityConverter x:Key="nullToVisibilityConverter" />
        <DataTemplate x:Key="OrderPresentationModelView">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100"/>
                    <ColumnDefinition  Width="*" MinWidth="90" />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Row="0" Grid.Column="0" Text="Name" Margin="0,0,0,10" />
                <TextBlock Grid.Row="1" Grid.Column="0" Text="Delivery Date"  />
                <TextBlock Grid.Row="2" Grid.Column="0" Text="Quantity"  />
                <TextBlock Grid.Row="3" Grid.Column="0" Text="Price"  />
                <TextBlock Grid.Row="4" Grid.Column="0" Text="Shipping" />
                <TextBlock Grid.Row="5" Grid.Column="0" Text="Total"  />
                <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Path=OrderName}"  HorizontalAlignment="Left" FontWeight="Bold"/>
                <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path=DeliveryDate, Mode=TwoWay, Converter={StaticResource dateConverter}}" AutomationProperties.AutomationId="DeliveryDateTextBox"/>
                <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Path=Quantity, Mode=TwoWay, Converter={StaticResource stringToNullableNumberConverter}}" AutomationProperties.AutomationId="QuantityTextBox"/>
                <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding Path=Price, Mode=TwoWay, Converter={StaticResource stringToNullableNumberConverter}}" AutomationProperties.AutomationId="PriceTextBox" />
                <TextBox Grid.Row="4" Grid.Column="1" Text="{Binding Path=Shipping, Mode=TwoWay, Converter={StaticResource stringToNullableNumberConverter}}" AutomationProperties.AutomationId="ShippingTextBox"  />
                <TextBox Grid.Row="5" Grid.Column="1" IsReadOnly="True"  Text="{Binding Path=Total, Mode=OneWay}" AutomationProperties.AutomationId="TotalTextBox" />
                <Button Grid.Row="6" Grid.Column="1" Content="Save" Command="{Binding Path=SaveOrderCommand}" AutomationProperties.AutomationId="SaveButton" />
            </Grid>
        </DataTemplate>
    </UserControl.Resources>
    <StackPanel>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width=".4*"/>
                <ColumnDefinition Width=".6*"/>
            </Grid.ColumnDefinitions>
            <Border Grid.Column="0" CornerRadius="4,4,4,4" BorderBrush="#193441" Background="#FCFFF5" BorderThickness="2,2,2,2" Margin="5" Padding="5">
                <ListBox AutomationProperties.AutomationId="OrderListView" ItemsSource="{Binding Orders}" SelectionMode="Single" Width="Auto" Height="Auto">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding OrderName}" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </Border>
            <Border Grid.Column="1" CornerRadius="4,4,4,4" BorderBrush="#193441" Background="#FCFFF5" BorderThickness="2,2,2,2" Margin="5" Padding="5">
                <ContentControl x:Name="SelectedOrderControl" Content="{Binding SelectedOrder}"  Visibility="{Binding SelectedOrder, Converter={StaticResource nullToVisibilityConverter}}" Width="Auto" Height="Auto" ContentTemplate="{StaticResource OrderPresentationModelView}"/>
            </Border>
        </Grid>
        <TextBlock Text="Please enter positive values for Quantity and Price" />
    </StackPanel>
</UserControl>
